<template>
	<view class="store_buy">
		<view class="close" @click="$emit('close')">
			<image :src="`${baseImageUrl}/common/close1.png`"></image>
		</view>
		<view class="title">
			<view>购买</view>
		</view>
		<view class="cover">
			<image :src="res.cover"></image>
		</view>
		<view class="tips">
			<view>是否花</view>
			<text>【{{res.total}}官银】</text>
			<view>购买{{res.name}}<text>*{{res.number}}</text>？</view>
		</view>
		<view class="btn_view">
			<view class="cancel" @click="$emit('close')">取消</view>
			<view class="confirm" @click="confirm">确定</view>
		</view>
	</view>
</template>

<script>
	// import {
	// 	captchaAppId
	// } from "@/utils/config";
	import {
		productInfo,
		productSilverBuy
	} from '@/request/api.js';
	export default {
		props: {
			res: {
				type: Object,
				default: {}
			}
		},
		methods: {
			async confirm() {
				if (this.is_click) {
					this.$u.toast("请等待服务器结果");
					return false;
				}
				this.is_click = true;
				let {
					id,
					number
				} = this.res;
				await productSilverBuy({
					id,
					number
				}, {
					custom: {
						catch: true,
						toast: false
					}
				}).then(res => {
					console.log(res)
					this.is_click = false;
					this.$emit('success', res.id);
				}).catch(err => {
					this.is_click = false;
					let msg = err.message;
					this.$emit('fail', msg);
				});
				// }, {});
				// captcha.show();
			}
		}
	}
</script>

<style scoped lang="scss">
	.store_buy {
		width: 688rpx;
		height: 700rpx;
		padding: 92rpx 0 120rpx;
		box-sizing: border-box;
		background: url(#{$baseImageUrl}/bg/688_700.png) no-repeat;
		background-size: 100% 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: center;
		position: relative;

		.close {
			width: 122rpx;
			height: 122rpx;
			position: absolute;
			right: 0rpx;
			top: 0rpx;
			transform: translate(50rpx, 0rpx);
			z-index: 2;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.title {
			display: flex;
			justify-content: center;
			align-items: center;

			view {
				width: 256rpx;
				height: 30rpx;
				line-height: 30rpx;
				text-align: center;
				color: #494338;
				font-size: 42rpx;
				font-weight: 400;
				font-family: LiSu;
				background: url(#{$baseImageUrl}/home/title.png) no-repeat;
				background-size: 100% 100%;
			}
		}

		.cover {
			display: flex;
			justify-content: center;

			image {
				width: 130rpx;
				height: 130rpx;
			}
		}

		.tips {
			color: #494338;
			font-size: 32rpx;
			font-weight: 400;
			font-family: SimSun;
			display: flex;
			justify-content: center;

			text {
				color: #CA372E;
			}
		}

		.btn_view {
			width: 100%;
			display: flex;
			justify-content: center;

			view {
				width: 210rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 30rpx;
				font-weight: 400;
				margin: 0 40rpx;
			}

			.cancel {
				background: url(#{$baseImageUrl}/common/btn2.png) no-repeat;
				background-size: 100% 100%;
			}

			.confirm {
				background: url(#{$baseImageUrl}/common/btn.png) no-repeat;
				background-size: 100% 100%;
			}
		}
	}
</style>